<?php
    define('ABSOLUTE_SERVER_REMOTE_ADDR','../../');
    define('ABSOLUTE_SERVER_DOCUMENT_ROOT','../../');
    define('ABSOLUTE_SERVER_HOST','/../../');

    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'session.inc';
    if(file_exists('../../../definitions.inc.php')) include_once('../../../definitions.inc.php');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'funct.inc');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'functs.inc');
    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'color_style.php';
    include ABSOLUTE_SERVER_DOCUMENT_ROOT.LANGUAGE;
    require_once('../../../classDB.inc.php');
    
    if(!GetAdminID($ID)){echo LOGIN_ERR;exit;}
    if(!Right_Check(6)){header('Location:'.ABSOLUTE_SERVER_DOCUMENT_ROOT.'error.php');exit;}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
        <?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>
        <?php include ABSOLUTE_SERVER_DOCUMENT_ROOT.'html_style.php';?>

</head>
<?php
print "<body bgcolor=\"".Background_Color."\">";

do
{
    $_DB = new classDB();
    if (!$_DB->open()){echo OPEN_DB_ERR; break;}

    if($_REQUEST["PageQuanter"]=="")
       $PageNo=$_REQUEST["PageNo"];
    else
       $PageNo=$_REQUEST["PageNo"]-1;

    if($PageNo=="" || $PageNo==-1) $PageNo=0;
 //Definicie tovarov=================================
    $ItemsOnPage = ITEMSONPAGE;
    $ShowQvantumPage = SHOWQVANTUMPAGE;
 //===================================================
    $ActualQvantumPage=$_REQUEST["ActualQvantumPage"];
    if($ActualQvantumPage=="")$ActualQvantumPage = 0;


    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene hore
    //
    //**************************************************************************
    $sql_psel= "SELECT COUNT(*) FROM top_user";//,users WHERE top_user.ID_top=users.ID";
    $sql_array_Prodct = mysql_fetch_row(mysql_query($sql_psel));

    if($sql_array_Prodct[0]/$ItemsOnPage==($PageNo)) $PageNo--;
    if($sql_array_Prodct[0]/$ItemsOnPage<=$ActualQvantumPage) $ActualQvantumPage=$ActualQvantumPage-$ShowQvantumPage;

   do{
      if (($sql_array_Prodct[0]/$ItemsOnPage)<=1) break;
      print"<center><table style=\"position:relative;  top:5px;\"><tr>";

// Podmienka prvej >>>> --------------------------------------------------------------------
      if(($sql_array_Prodct[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"top_user.php\" target=\"place\" method=\"post\">";
             if($sql_array_Prodct[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";

             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

 //podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_Prodct[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_Prodct[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_Prodct[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_Prodct[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------
      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
      print "<form  action=\"top_user.php\" target=\"place\" method=\"post\">";
          print "<td>";
          $Xi=$i+1;
          if($PageNo==$i)
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\" />";
          else
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
          print "<input type=\"hidden\" value=\"1\" name=\"PageQuanter\" />";
          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
          print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
          print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
          print "</form>";
          print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
    if(($sql_array_Prodct[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"top_user.php\" target=\"place\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
              onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
              onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
      print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
      print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
    print "</form>";
    print "</td>";
     }
 //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
    PrintLine();
    }while(false);

    print "<br />";

    //**************************************************************************
    //
    //Naplneneie obsahu stranky datami z databazy
    //
    //**************************************************************************
        $From   = $PageNo*$ItemsOnPage;
        if($From<0) $From=0;

        //$sql_psel="DELETE FROM top_user WHERE top_user.ID_top!=products.ID";
        
        $sql_top= "SELECT ID_top,Top_Count,Top_price FROM top_user,users WHERE top_user.ID_top=users.ID ORDER BY Top_price DESC LIMIT ".$From.",".$ItemsOnPage;
        $Product_source = mysql_query($sql_top);
        
		//$sql_psel= "SELECT * FROM top_user ORDER BY top_count LIMIT ".$From.",".$ItemsOnPage;
        //$Product_source = mysql_query($sql_psel);
        
        $sql_top= "SELECT MAX(Top_price) FROM top_user";
        $top_koeficient_sql = mysql_fetch_row(mysql_query($sql_top));
		if($top_koeficient_sql[0])
			$top_koeficient=200/$top_koeficient_sql[0];
        
        $counter=0;
        
        //hlavicka tabulky
        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".BUTTON_ON_OVER."\">";
			    print "<tr>";
			    
     			print "<td  align=\"left\" width=\"150px\">";
     				print "<b>".TU_MENO."</b>";
				print "</td>";
				print "<td  align=\"left\" width=\"150px\">"; 
					print "<b>".TU_PRIEZVISKO."</b>";
				print "</td>";
				print "<td  align=\"left\" width=\"100px\">";
					print "<b>".TU_MESTO."</b>";
				print "</td>";
				print "<td  align=\"left\" width=\"100px\">";
					print "<b>".TU_ORGANIZACIA."</b>";
				print "</td>";
				print "<td  align=\"left\" width=\"80px\">";
					print "<b>".TU_POCET_OBJEDNAVOK."</b>";
				print "</td>";
				print "<td  align=\"right\" width=\"200px\">";
					print "<b>".TU_SUCET_CIEN_OBJEDNAVOK."</b>";
				print "</td>";
				print "<td  align=\"left\" width=\"180px\">";
				print "</td>";
     			print "</tr>";
        print "</table>";
                
     while($sql_array_Prodct = mysql_fetch_object($Product_source))
     {		
       		//U_Name,U_Surname,U_City,U_Organisation
	   		$sql_top_detail= "SELECT U_Name,U_Surname,U_City,U_Organisation FROM users WHERE ID=".$sql_array_Prodct->ID_top;
     		$Product_top_detail = mysql_fetch_object(mysql_query($sql_top_detail));
     		
			if(($counter%2))
            	print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
        	else
            	print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";
			    print "<tr>";
			    
     			print "<td  align=\"left\" width=\"150px\">";
					print "<b>".$Product_top_detail->U_Surname."</b>"; 
				print "</td>";
				print "<td  align=\"left\" width=\"150px\">"; 
					print "<b>".$Product_top_detail->U_Name."</b>";
				print "</td>";
				print "<td  align=\"left\" width=\"100px\">"; 
					print $Product_top_detail->U_City;
				print "</td>";
				print "<td  align=\"left\" width=\"100px\">"; 
					print $Product_top_detail->U_Organisation;
				print "</td>";
				print "<td  align=\"left\" width=\"40px\">"; 
					print $sql_array_Prodct->Top_Count;
				print "</td>";
				print "<td  align=\"right\" width=\"140px\">"; 
					print "<b>".RoundIt($sql_array_Prodct->Top_price)."</b> ".D_MENA;
				print "</td>";
				print "<td  align=\"left\" width=\"210px\"> 
						<img src=\"baner.jpg\" height=\"10px\"  width=\"".$sql_array_Prodct->Top_price*$top_koeficient."px\"  />";
				print "</td>";//width=\"210px\"
				
     			print "</tr>";
                print "</table>";
                $counter++;
      }


        print "<br />";
        PrintLine();

    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene dole
    //
    //**************************************************************************
    $sql_psel= "SELECT COUNT(*) FROM top_user";//,users WHERE top_user.ID_top=users.ID";
    $sql_array_Prodct = mysql_fetch_row(mysql_query($sql_psel));
    do{
      if (($sql_array_Prodct[0]/$ItemsOnPage)<=1) break;
      print"<center><table><tr>";

// Podmienka prvej >>>> --------------------------------------------------------------------
           if(($sql_array_Prodct[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"top_user.php\" target=\"place\" method=\"post\">";
             if($sql_array_Prodct[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
               print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
               print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

//podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_Prodct[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_Prodct[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_Prodct[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_Prodct[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------
      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
      print "<form  action=\"top_user.php\" target=\"place\" method=\"post\">";
          print "<td>";
          $Xi=$i+1;
          if($PageNo==$i)
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\">";
          else
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
          print "<input type=\"hidden\" value=\"1\" NAME=\"PageQuanter\">";
          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" NAME=\"ActualQvantumPage\">";
          print "<input type=\"hidden\" value=\"".$Path."\" NAME=\"path\">";
          print "<input type=\"hidden\" value=\"".$Category_ID."\" NAME=\"ID\">";
          print "</form>";
          print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
if(($sql_array_Prodct[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"top_user.php\" target=\"place\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
      print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
      print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
    print "</form>";
    print "</td>";
    }
 //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
    PrintLine();
    }while(false);




        mysql_close();
}
while(false)
?>


</body>
</html>